/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.documentar.DAO;

import br.com.documentar.interfacee.InterfaceDAO;
import br.com.documentar.model.VersionamentoModel;
import java.sql.SQLException;
import java.util.List;

/**
 *
 * @author Santos
 */
public class VersionamentoDAO extends AbstractDAO implements InterfaceDAO<List<VersionamentoModel>, VersionamentoModel> {

    @Override
    public boolean setDados(VersionamentoModel model) {
        String sql = null;
        ConnectDataBase();
        switch (model.getActionScript()) {
            case "I":
                sql = "";
                break;
            case "U":
                sql = "";
                break;
            case "D":
                sql = "";
                break;
        }
        return InsertUpdateDelete(sql, model.getNomeTela());
    }

    @Override
    public List<VersionamentoModel> getDados(VersionamentoModel model) {
        model.setResultSet(null);
        model.getListaVersionamento().clear();
        String sql = "SELECT \n"
                + "  `TCON_CODIGO_PK`,\n"
                + "  `TCON_NOME`,\n"
                + "  `TCON_DATA_LIBERACAO`,\n"
                + "  `TCON_ATIVA`\n"
                + " FROM \n"
                + "   `tcon_controle_versao` versionamento \n"
                + " where `versionamento`.`TCON_ATIVA` = 'S'";
        try {
            ConnectDataBase();
            switch (model.getActionScript()) {
                case "C":
                    model.setResultSet(Select(sql, model.getNomeTela()));
                    break;
            }
            while (model.getResultSet().next()) {
                br.com.documentar.model.VersionamentoModel p = new br.com.documentar.model.VersionamentoModel();
                p.setCodigo(rs.getInt("TCON_CODIGO_PK"));
                p.setNome(rs.getString("TCON_NOME"));
                p.setDataLiberacao(rs.getString("TCON_DATA_LIBERACAO"));
                p.setAtivo(rs.getString("TCON_ATIVA"));
                model.getListaVersionamento().add(p);
            }
        } catch (SQLException ex) {
            ex.getStackTrace();
        } finally {
            Desconectar(model.getNomeTela());
        }
        return model.getListaVersionamento();
    }
}
